/* 
 * File:   TemperatureStuff.h
 * Author: drbobbob
 *
 * Created on May 25, 2014, 6:03 PM
 */

#ifndef TEMPERATURESTUFF_H
#define	TEMPERATURESTUFF_H

#include "CanMessage.h"

//Max is 7 so that it will fit in a single CAN message
#define MAX_DEVICE_COUNT 7

extern int DevicesConnected;
extern int TemperatureReadings[MAX_DEVICE_COUNT];

typedef struct {
    unsigned char SA;
    unsigned char tempValues[7];
    int age;
} ExternalSensorPacket;


#define MAX_EXTERNAL_DEVICES 5
extern int ExternalDeviceCount;
extern ExternalSensorPacket ExternalData[MAX_EXTERNAL_DEVICES];


void ScanForSerialNumbers();
void InitializeTemperatureStuff();
void PrintAllSerialNumbers();
void GetAllTemperatures();
void PrintAllTemperatures();
void ChangeTo9BitConversion();

unsigned char ConvertCelciusToCAN(int temperature);

void SendTemperatureMessage();

void TS_HandleExternalTemperatureMessage(int SID, int EID, unsigned char* data);
void TS_HandleExternalTemperatureMessageNew(CANMessage*);
void TS_HandleTimerTick();
void TS_ProcessMainLoop();

#endif	/* TEMPERATURESTUFF_H */

